css加载动画小栗子

地址就放在这了

今天在油管看到 up 主分享的一个 css 加载动画实现过程,这里记录分享下。

废话不多说,直接上代码,代码很简单。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="loading">
<span>Loading...</span>
</div>
</body>
</html>
body {
margin: 0;
padding: 0;
background-color: #34495e;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

.loading {
position: relative;
width: 200px;
height: 200px;
border-radius: 50%;
box-sizing: border-box;
border-top: 10px solid #e74c3c;
animation: a1 2s linear infinite;
}

.loading::before,
.loading::after {
content: '';
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: -10px;
box-sizing: border-box;
border-radius: 50%;
}

.loading::before {
border-top: 10px solid #e67e22;
transform: rotate(120deg);
}

.loading::after {
border-top: 10px solid #3498db;
transform: rotate(240deg);
}

.loading span {
position: absolute;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
color: #fff;
animation: a2 2s linear infinite;
}

@keyframes a1 {
to {
transform: rotate(360deg);
}
}

@keyframes a2 {
to {
transform: rotate(-360deg);
}
}

效果主要是运用圆角和旋转来实现的。